home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / keyb / kb84fix.zip / KB84FIX.ASM < prev    next >
Assembly Source File  |  1990-03-06  |  4KB  |  164 lines

  1. ; ======================================================================
  2. ;
  3. ;    KB84FIX.ASM
  4. ;
  5. ;    (C) Copyright 1990 Richard B. Wales <wales@CS.UCLA.EDU>
  6. ;    May be distributed and used freely, so long as the original
  7. ;    source is included in any distribution, no charge (other than
  8. ;    a nominal communications or handling charge) is assessed, and
  9. ;    this notice is retained intact.
  10. ;
  11. ;    This TSR hooks into Int 9H and switches the BKSP, ESCAPE, and
  12. ;    Tilde/Grave keys on an 84-key keyboard.  It needs to be loaded
  13. ;    as early as possible -- before any other TSR's that hook into
  14. ;    the Int 9H vector.
  15. ;
  16. ;    I wrote this program because I wanted the keys on the top row
  17. ;    of my home "clone" system to be arranged in the same way as on
  18. ;    the Sun 3/50 workstation I use at school.  I pried off the caps
  19. ;    for the three keys in question; this TSR intercepts the key-
  20. ;    strokes and makes the keys generate the characters on the caps.
  21. ;
  22. ;    This program should be readily adaptable to other applications
  23. ;    that need to swap keys (e.g., a Dvorak keyboard mapper) or
  24. ;    otherwise manipulate the BIOS keystroke buffer.  Note, however,
  25. ;    that I assume each keystroke will result in at most one entry
  26. ;    being placed in the BIOS buffer; hence, this program would have
  27. ;    to be modified somewhat to work with an "extended" keyboard.
  28. ;
  29. ;    Assembled using Microsoft Assembler (MASM) version 5.1.  After
  30. ;    assembly and linkage, use EXE2BIN to convert the program into a
  31. ;    .COM file.
  32. ;
  33. ; ======================================================================
  34.  
  35. ; Segment 0000H (interrupt vectors)
  36. INTVECS    segment    at 0000H
  37.     org    24H
  38. int9vec    dw    ?        ; Interrupt vector 09H
  39.     dw    ?
  40. INTVECS    ends
  41.  
  42. ; Segment 0040H (BIOS data area)
  43. BIOSDTA    segment    at 0040H
  44.     org    17H
  45. kbflags    db    ?        ; Keyboard flags
  46.     org    1CH
  47. buftail    dw    ?        ; Tail pointer (character buffer)
  48. BIOSDTA    ends
  49.  
  50. ; Shift-key mask for kbflags
  51. SHFTMSK    equ    03H        ; look for left and/or right shift key
  52.  
  53. ; Character codes we are interested in changing
  54. ESCAPE    equ    011BH        ; escape
  55. BKSP    equ    0E08H        ; backspace
  56. GRAVE    equ    2960H        ; grave accent
  57. TILDE    equ    297EH        ; tilde
  58.  
  59. ; ======================================================================
  60.  
  61. CODESEG    segment
  62.     assume    cs:CODESEG, ds:BIOSDTA
  63.     org    100H
  64.  
  65. ; Buffer to hold address of original system Int 9H
  66. ; (will overlay the "jmp" at the start of the program)
  67. oldint9    label    dword
  68.  
  69. begin:    jmp    short init    ; Will be overlaid by "oldint9" value
  70.     dw    0        ; ditto
  71.  
  72. ; New Int 9H handler
  73. newint9    proc    far
  74.  
  75.     ; Save the registers we'll be playing with
  76.     push    ax
  77.     push    bx
  78.     push    dx
  79.     push    ds
  80.  
  81.     ; Establish the BIOS segment register for accessing BIOS data
  82.     mov    ax, seg BIOSDTA
  83.     mov    ds, ax
  84.  
  85.     ; Get the tail pointer to the character buffer
  86.     mov    bx, [buftail]
  87.  
  88.     ; Call the original (BIOS) Int 9H routine first, and
  89.     ; let it put a new character into the circular buffer
  90.     pushf
  91.     call    [oldint9]
  92.  
  93.     ; Did the BIOS routine add a character to the buffer?
  94.     ; If so, copy it into a register so we can examine it
  95.     cmp    bx, [buftail]
  96.     je    short done
  97.     mov    dx, [bx]
  98.  
  99.     ; Check for the four codes of interest, and switch them around
  100.  
  101.     ; ESCAPE -> BKSP
  102.     cmp    dx, ESCAPE
  103.     jne    short notesc
  104.     mov    [bx], BKSP
  105.     jmp    short done
  106. notesc:
  107.  
  108.     ; (GRAVE or TILDE) -> ESCAPE
  109.     cmp    dx, GRAVE
  110.     jne    short notgrv
  111. makesc:    mov    [bx], ESCAPE
  112.     jmp    short done
  113. notgrv:    cmp    dx, TILDE
  114.     je    short makesc
  115.  
  116.     ; BKSP -> GRAVE (if unshifted) or TILDE (if shifted)
  117.     cmp    dx, BKSP
  118.     jne    short done
  119.     test    byte ptr kbflags, SHFTMSK
  120.     jnz    short shift
  121.     mov    [bx], GRAVE
  122.     jmp    short done
  123. shift:    mov    [bx], TILDE
  124.  
  125.     ; All done.
  126. done:    pop    ds
  127.     pop    dx
  128.     pop    bx
  129.     pop    ax
  130.     iret
  131. newint9    endp
  132.  
  133. ; ======================================================================
  134.  
  135. ; TSR initialization code
  136.  
  137. init:
  138.     assume    ds:INTVECS
  139.  
  140.     ; Establish a zero segment register for interrupt vector area
  141.     xor    ax, ax
  142.     mov    ds, ax
  143.  
  144.     ; Save the old Int 9H pointer
  145.     mov    ax, [int9vec]
  146.     mov    word ptr oldint9, ax
  147.     mov    ax, [int9vec+2]
  148.     mov    word ptr oldint9[2], ax
  149.  
  150.     ; Hook in the new Int 9H handler
  151.     cli
  152.     mov    ax, offset newint9
  153.     mov    [int9vec], ax
  154.     mov    ax, cs
  155.     mov    [int9vec+2], ax
  156.     sti
  157.  
  158.     ; Exit via a TSR call
  159.     mov    dx, offset init
  160.     int    27H
  161.  
  162. CODESEG    ends
  163.     end    begin
  164.